package middleware

import (
    "net/http"
    "github.com/gin-gonic/gin"
    "github.com/sirupsen/logrus"
)

func RecoveryMiddleware() gin.HandlerFunc {
    return func(c *gin.Context) {
        defer func() {
            if err := recover(); err != nil {
                logrus.WithField("error", err).Error("Recovered from panic")
                c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "Internal server error"})
            }
        }()

        c.Next()
    }
}